import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users

import util

class MainPageHandler(webapp.RequestHandler):
  def get(self):
    #self.response.headers['Content-Type'] = 'text/plain'
    template_values = {}
    user = users.get_current_user()
    if user:
      template_values['user_email'] = user.email()
      template_values['logout_url'] = users.create_logout_url(self.request.uri)
    else:
      template_values['login_url'] = users.create_login_url(self.request.uri)
      
    util.render_template(self, 'main.tpl', template_values)

application = webapp.WSGIApplication(
                                     [('/', MainPageHandler)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
